#!/usr/bin/env bash


help(){
    cat<<__EOF__
    usage: m screensaver [ askforpassword | help ]

    Examples:
      m screensaver                         # launch screensaver

      m screensaver askforpassword          #  get the current status
      m screensaver askforpassword YES      #  enable password requirement to unlock
      m screensaver askforpassword NO       #  disable password requirement to unlock
__EOF__
}

askforpassword(){
    case $1 in
        [yY][eE][sS])
            defaults write com.apple.screensaver askForPassword -int 1
            echo "Screensaver askforpassword: YES"
            ;;
        [nN][oO])
            defaults write com.apple.screensaver askForPassword -int 0
            echo "Screensaver askforpassword: NO"
            ;;
        *)
            VALUE=$(defaults read com.apple.screensaver askForPassword)
            if [ "${VALUE}" -eq 1 ]; then
                echo "Screensaver askforpassword: YES"
            else
                echo "Screensaver askforpassword: NO"
            fi
            ;;
    esac
}


case $1 in
    help)
        help
        ;;
    askforpassword)
        shift
        askforpassword $@
        ;;
    *)
        open /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app
        ;;
esac

# vim: ts=4 sw=4 softtabstop=4 expandtab
